<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <my-father></my-father>
    </div>

    <!--父组件-->
    <template id="father">
        <div>
            <h2>我是父组件{{num}}</h2>
            <button @click="add">+</button>
            <my-son :num="num"></my-son>
        </div>
    </template>

    <!-- 子组件 -->
    <template id="son">
        <div>
            <h6>我是子组件{{num}}</h6>
        </div>
    </template>

    <script src="./vue.js"></script>
    <script>

        //父组件向子组件传递数据
        //1.在子组件标签上自定义属性,值为要传递的数据
        //2.在子组件内部通过props属性来接受(接收完成后通过this可直接访问)

        //子组件
        const Son = {
            template: "#son",
            //用来接收父元素传递的内容
            props:["num"],
        }

        //父组件
        const Father = {
            template: "#father",
            data(){
                return{
                    num:666
                }
            },
            components: {
                "my-son": Son,
            },
            methods:{
                add(){
                    this.num+=1
                }
            }
        }


        new Vue({
            el: "#app",
            //注册组件
            //components:{组件名称：组件内容}
            components: {
                "my-father": Father,
            },
        })
    </script>
</body>

</html>